*** Descriptive kernel density plots by treatment (anchoring at 100%) ***

use "$dta/SS1and2.dta", clear

//StewardShares I

twoway kdensity realbid  if slidervariation &  agvise == 1, bwidth(.2) ///
 xtitle("Cost-sharing bid (fraction)") ytitle(Density) ///
color(blue*.5) lcolor(gs1)  lwidth(medthick)  || ///
kdensity realbid if !slidervariation & agvise == 1 , bwidth(.2)   ///
color(red*.1) lcolor(gs11) lpattern(dash) lwidth(medthick) ///
legend(order(1 "Default 100%" 2 "Default 0%") row(1) pos(6) ring(1) size(small)) ///
title(StewardShares I , size(small) span box  color(black) bcolor(gs14) ) ///
scheme(plotplain) xlab(, nogrid) ylab(, nogrid) scale(1.5) 

graph save agvise1, replace 

graph export "${outputs}/distplot_agvise1.png" , as(png) replace 


//StewardShares II 

use "$dta/SS1and2.dta", clear


twoway kdensity realbid  if slidervariation &  agvise == 2, bwidth(.2) ///
xtitle("Cost-sharing bid (fraction)") ytitle(Density) ///
color(blue*.5) lcolor(gs1)  lwidth(medthick)  || ///
kdensity realbid if !slidervariation & agvise == 2 ,  bwidth(.2)  ///
color(red*.1) lcolor(gs11) lpattern(dash) lwidth(medthick) ///
legend(order(1 "Default 100%" 2 "Default 0%") row(1) pos(6) ring(1) size(small)) ///
title(StewardShares II, size(small) span box  color(black) bcolor(gs14) ) ///
scheme(plotplain) xlab(, nogrid) ylab(, nogrid) scale(1.5)

graph save agvise2, replace 

graph export "${outputs}/distplot_agvise2.png" , as(png) replace 


//StewardShares III

use "$dta/SS3.dta", clear

#delimit ;

twoway kdensity fracbid if default, bwidth(.1) 
	xtitle("Cost-sharing bid (fraction)") ytitle(Density) 
	color(blue*.5) lcolor(gs1)  lwidth(medthick)  || 
	kdensity fracbid if !default ,  bwidth(.1)  
	color(red*.1) lcolor(gs11) lpattern(dash) lwidth(medthick) 
	legend(order(1 "Default 100%" 2 "Default 0%") row(1) pos(6) ring(1) size(small))
	title(StewardShares III , size(small) span box  color(black) bcolor(gs14) ) 
	scheme(plotplain) xlab(, nogrid) ylab(, nogrid) scale(1.5) ;

#delimit cr


graph save agvise3, replace 

graph export "${outputs}/distplot_hogvise.png" , as(png) replace 



//AgVise + HogVise pooled 
use "$dta/SSpooled.dta", clear 


twoway kdensity fracbid if default,  bwidth(.1) xtitle("Cost-sharing bid (fraction)") ytitle(Density) ///
color(blue*.5) lcolor(gs1)  lwidth(medthick)  || ///
kdensity fracbid if !default ,  bwidth(.1)   ///
color(red*.1) lcolor(gs11) lpattern(dash) lwidth(medthick) ///
legend(order(1 "Default 100%" 2 "Default 0%") row(1) pos(6) ring(1)) ///
title(Pooled ,  size(small) span box  color(black) bcolor(gs14) ) ///
scheme(plotplain) xlab(, nogrid) ylab(, nogrid) scale(1.5) 

graph save pooled, replace 

graph export "${outputs}/distplot_aghogvise.png" , as(png) replace  

*combine graph using package grc1leg2 

#delimit ;
grc1leg2  agvise1.gph agvise2.gph agvise3.gph pooled.gph, 
	xcommon  ring(1) pos(6) span
	legendfrom(agvise1.gph) xtob1title  ytol1title
	scheme(plotplain)	;
#delimit cr 

graph export "$outputs/distplot_agvise1_2_3.png", replace

erase agvise1.gph 
erase agvise2.gph 
erase agvise3.gph 
erase pooled.gph

*** Descriptive plots: average outcomes by treatment status ***


** SS I and II **
use "$dta/SS1and2.dta", clear 


* label variables for use in graph output
lab def treat 0 "0%" 1 "100%"
la val slidervariation treat 
ta slidervariation, gen(treatdumm)
foreach var of varlist treatdumm* {  
  local l: var label `var'
  local l2: subinstr local l "slidervariation=="   " "
  lab var `var' "`l2'"
}

*regress outcome on treatment dummies (fully saturated model with no constant)
* to get mean and SE by group:
* then store estimates for plotting

reg realbid treatdumm* if agvise == 1  ,   baselevels nocons
eststo agvise1 

reg realbid treatdumm* if agvise == 2  ,   baselevels nocons
eststo agvise2 

** SS III **
use "$dta/SS3.dta", clear 

lab def treat 0 "0%" 1 "100%"
la val default treat 
ta default, gen(treatdumm)
foreach var of varlist treatdumm* {  
  local l: var label `var'
  local l2: subinstr local l "default=="   " "
  lab var `var' "`l2'"
}

reg fracbid treatdumm* , baselevels nocons
eststo agvise3 

** Pooled **

use "$dta/SSpooled.dta", clear 

lab def treat 0 "0%" 1 "100%"
la val default treat 
ta default, gen(treatdumm)
foreach var of varlist treatdumm* {  
  local l: var label `var'
  local l2: subinstr local l "default=="   " "
  lab var `var' "`l2'"
}

reg fracbid treatdumm* , baselevels nocons
eststo pooled 



/* plot graph */

#delimit ;

coefplot agvise1 , bylabel(StewardShares I)  || agvise2, bylabel(StewardShares II) || 
		agvise3, bylabel(StewardShares III) ||  pooled, bylabel(Pooled) || , 
	baselevels  vertical  
	yline(0) recast(bar) barwidt(0.3) color(gs11)
	order(treatdumm2 treatdumm1 ) 
	ciopts(recast(rcap) lpattern(dash)) citop 
	xtitle("Default cost-sharing bid option")
	ytitle("Cost-sharing bid" "Mean and 95% CI" ) 
	ylab(0(0.1)0.5 , nogrid) xlab(, labsize(small)) nooffsets 
	scheme(plotplainblind) byopts(iscale(*1.5) row(1) ) 
	subtitle(, size(*0.7) margin(medium) justification(center)      // code to modify title format of each sub-graph panel
           color(black) bcolor(gs14) bmargin(top_bottom))
	format(%9.2f) addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black)) ;  //adding value labels 

#delimit cr

graph export "$outputs/meanplot_agvise1_2_3.png", replace
